package com.newland.starpos.partner.controller.advice;

import com.newland.starpos.partner.exception.CustomException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.stream.Collectors;

/**
 * Created by liuNW on 2018/9/29.
 */
public abstract class BaseController {
    // 统一的请求参数验证,直接返回所有message
    protected void checkBindResult(BindingResult bind) throws CustomException {
        if(bind.hasErrors()){
            String message = bind.getAllErrors().stream()
                    .map((ObjectError s) -> s.getDefaultMessage())
                    .collect(Collectors.joining(","));
            throw new CustomException(45000, message);
        }
    }
}
